from concurrent.futures import ThreadPoolExecutor
import sys
import os
import threading
import time


sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from common.logger import logger
from manager.lock_manager import LockManager
import spider_config


def test2(account):
    with LockManager.instance().get(spider_config.su_park_id, account):
        print(f"线程{threading.get_ident()} {account} 获取锁")
        time.sleep(1)


def test(account):
    with LockManager.instance().get(spider_config.su_park_id, account):
        print(f"线程{threading.get_ident()} {account} 获取锁")
        test2(account)


if __name__ == "__main__":
    thread_count = 10

    thread_pool = ThreadPoolExecutor(max_workers=thread_count)

    futures = []
    for i in range(thread_count):
        futures.append(thread_pool.submit(test, i % 3))

    thread_pool.shutdown(wait=True)
